//
//  photoScrollView.m
//  HuiWenMovie
//
//  Created by niceDay on 15/7/23.
//  Copyright (c) 2015年 computer. All rights reserved.
//

#import "photoScrollView.h"
#import "UIImageView+WebCache.h"
@implementation photoScrollView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self addSubview:imageView];
        self.delegate = self;
        self.minimumZoomScale = 1;
        self.maximumZoomScale = 3;
        
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleAction)];
        doubleTap.numberOfTapsRequired = 2;
        [self addGestureRecognizer:doubleTap];
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleAction)];
        singleTap.numberOfTapsRequired = 1;
        [self addGestureRecognizer:singleTap];
        
        
        [singleTap requireGestureRecognizerToFail:doubleTap];
    }
    
    return self;
}

- (void)doubleAction{
    if (self.zoomScale == 1) {
        [self setZoomScale:3 animated:YES];
    }
    else{
        [self setZoomScale:1 animated:YES];
    }
    
}

- (void)singleAction{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"HiddenNavidationBar" object:nil];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return imageView;
}

- (void)setImageUrl:(NSString *)imageUrl{
    _imageUrl = imageUrl;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self setNeedsLayout];
}

- (void)layoutSubviews{
    [imageView sd_setImageWithURL:[NSURL URLWithString:_imageUrl]];
    
}
@end
